package com.common.aspect;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import com.common.util.Response;
import com.common.util.Status;

//停用
//@Aspect
public class ResponseControllerAspect {

    private Logger logger = Logger.getLogger(this.getClass());

    public ResponseControllerAspect(){
    }

    @Around("execution(Object com.scs.controller.*.*(..))")
    public Object process(ProceedingJoinPoint jp) throws Throwable {
    	
        Object result = jp.proceed();

        if(result==null) return new Response(Status.FAILED,Status.getResponseMsg(Status.FAILED),null);

        if(result instanceof  Integer){
            int status = (Integer) result;
            return new Response(status,Status.getResponseMsg(status),null);
        }
        if(result instanceof  Response){
            return result;
        }
        return new Response(Status.SUCCESS,Status.getResponseMsg(Status.SUCCESS),result);
    }
}